﻿package mortal.game.view.common.util
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import extend.language.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.util.*;

    public class AttributeUtil extends Object
    {
        public static var attrNames:Array = Language.getString(20217).split(" ");
        public static var attrs:Array = ["attack", "life", "mana", "physDefense", "magicDefense", "penetration", "crit", "toughness", "hit", "jouk", "expertise", "block", "damageReduce"];
        public static const attrTypeToName:Array = Language.getString(20867).split(",");
        public static const combatRatioList:Array = [1, 40, 2, 1.8, 1.8, 0.9, 1, 1, 0.9, 0.9, 1.5, 1.5, 1];

        public function AttributeUtil()
        {
            return;
        }// end function

        public static function getAttrNameByTypeValue(param1:int, param2:int = 0) : String
        {
            if (param1 == -1)
            {
                return Language.getString(20868);
            }
            if (param1 == 1 && param2 != 0)
            {
                if (param2 == ECareer._ECareerWarrior || param2 == ECareer._ECareerArcher)
                {
                    return Language.getString(20869);
                }
                return Language.getString(20870);
            }
            return String(attrTypeToName[param1]);
        }// end function

        public static function getEquipmentBasicAttrs(param1:Object, param2:Number) : Vector.<AttributeData>
        {
            var _loc_5:int = 0;
            var _loc_6:AttributeData = null;
            var _loc_3:* = new Vector.<AttributeData>;
            var _loc_4:int = 0;
            while (_loc_4 < attrs.length)
            {
                
                _loc_5 = param1[attrs[_loc_4]];
                if (_loc_5 > 0)
                {
                    _loc_6 = new AttributeData();
                    _loc_6.value = _loc_5 * (1 + param2);
                    _loc_6.type = _loc_4;
                    _loc_6.name = attrNames[_loc_4] as String;
                    _loc_6.attrName = attrs[_loc_4];
                    _loc_3.push(_loc_6);
                }
                _loc_4++;
            }
            return _loc_3;
        }// end function

        public static function getEquipRefreshProp(param1:ItemData, param2:ItemExInfo = null) : Vector.<AttributeData>
        {
            var _loc_5:int = 0;
            var _loc_6:AttributeData = null;
            var _loc_3:* = new Vector.<AttributeData>;
            var _loc_4:* = param2;
            if (_loc_4 == null && param1 != null && param1.extInfo != null)
            {
                _loc_4 = param1.extInfo;
            }
            if (_loc_4 != null)
            {
                _loc_5 = 1;
                while (_loc_5 <= 6)
                {
                    
                    if (_loc_4["addStar" + _loc_5] != 0 && _loc_4["addStar" + _loc_5] != -1)
                    {
                        _loc_6 = new AttributeData();
                        _loc_6.type = _loc_4["addition" + _loc_5];
                        _loc_6.name = ForgingUtil.instance.getAttrNameByType(_loc_4["addition" + _loc_5]);
                        _loc_6.value = ForgingUtil.instance.getAddtionValue(_loc_4["addition" + _loc_5], _loc_4["addStar" + _loc_5]);
                        _loc_6.baseValue = 0;
                        if (_loc_6.type == StrengUtil.getEquipHotAttrType(param1.itemInfo.type))
                        {
                            _loc_6.baseValue = _loc_6.value * 0.5;
                            _loc_6.value = _loc_6.value * 1.5;
                        }
                        _loc_6.attrName = int(_loc_4["addStar" + _loc_5]).toString();
                        _loc_3.push(_loc_6);
                    }
                    _loc_5++;
                }
            }
            return _loc_3;
        }// end function

        public static function transferAttrName(param1:String, param2:Boolean = false) : String
        {
            var _loc_3:* = GameDefConfig.instance.getAttributeName(param1, true);
            if (!param2)
            {
                _loc_3 = _loc_3.replace(/([ 　]{1})""([ 　]{1})/g, "");
            }
            return _loc_3;
        }// end function

        public static function transferSpecialAttr(param1:String) : String
        {
            var _loc_2:* = param1;
            if (param1 == "maxLife")
            {
                _loc_2 = "life";
            }
            if (param1 == "maxMana")
            {
                _loc_2 = "mana";
            }
            return _loc_2;
        }// end function

        public static function setAttrByObj(param1:Object, param2:int = 1, param3:Vector.<GTextFiled> = null, param4:Vector.<GTextFiled> = null, param5:Boolean = false) : String
        {
            var _loc_8:String = null;
            var _loc_9:int = 0;
            var _loc_10:String = null;
            var _loc_6:String = "";
            var _loc_7:int = 0;
            for each (_loc_10 in attrs)
            {
                
                if (param1.hasOwnProperty(_loc_10))
                {
                    _loc_8 = GameDefConfig.instance.getAttributeName(_loc_10, false, 1);
                    _loc_9 = param1[_loc_10];
                    if (param5)
                    {
                        _loc_6 = _loc_6 + (_loc_7 % param2 == (param2 - 1) ? (_loc_8 + "  " + _loc_9 + "<br>") : (_loc_8 + "  " + _loc_9));
                        if (param3)
                        {
                            GTextFiled(param3[_loc_7]).text = _loc_8;
                            GTextFiled(param4[_loc_7]).text = _loc_9.toString();
                        }
                        _loc_7++;
                        continue;
                    }
                    if (!param5 && _loc_9 > 0)
                    {
                        _loc_6 = _loc_6 + (_loc_7 % param2 == (param2 - 1) ? (_loc_8 + "  " + _loc_9 + "<br>") : (_loc_8 + "  " + _loc_9));
                        if (param3)
                        {
                            GTextFiled(param3[_loc_7]).text = _loc_8;
                            GTextFiled(param4[_loc_7]).text = _loc_9.toString();
                        }
                        _loc_7++;
                    }
                }
            }
            return _loc_6;
        }// end function

        public static function getTipsByAttrName(param1:String) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case "attack":
                {
                    _loc_2 = Language.getString(20871);
                    break;
                }
                case "life":
                {
                    _loc_2 = Language.getString(20872);
                    break;
                }
                case "mana":
                {
                    _loc_2 = Language.getString(20873);
                    break;
                }
                case "physDefense":
                {
                    _loc_2 = Language.getString(20874);
                    break;
                }
                case "magicDefense":
                {
                    _loc_2 = Language.getString(20875);
                    break;
                }
                case "penetration":
                {
                    _loc_2 = Language.getString(20876);
                    break;
                }
                case "jouk":
                {
                    _loc_2 = Language.getString(20877);
                    break;
                }
                case "hit":
                {
                    _loc_2 = Language.getString(20878);
                    break;
                }
                case "crit":
                {
                    _loc_2 = Language.getString(20879);
                    break;
                }
                case "toughness":
                {
                    _loc_2 = Language.getString(20880);
                    break;
                }
                case "block":
                {
                    _loc_2 = Language.getString(20881);
                    break;
                }
                case "expertise":
                {
                    _loc_2 = Language.getString(20882);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

    }
}
